package joyi.train.employee.controller;

import j.util.New;
import j.util.StringUtils;
import j.util.jdbc.JdbcTemplate;
import j.util.json.JsonUtils;
import j.util.web.ApplicationBean;
import j.util.web.BaseController;
import j.util.web.HttpView;
import j.util.web.WebRequest;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * Created by WY2015092804 on 2015/10/20.
 */
@WebServlet(urlPatterns = "/user/employee/manager")
public class EmployeeController extends BaseController {
    @ApplicationBean
    private JdbcTemplate jdbcTemplate ;

    @Override
    public void doDefaultGet(HttpView view) throws ServletException, IOException {

    }
    @WebRequest(action = "position")
    public void QueryPosition(HttpView view) throws ServletException, IOException {
        List<Map<String,Object>> list = jdbcTemplate.queryForListMap("select positionId value,positionName text from cw_Position");
            String method = view.getParameter("method");
        if("query".equals(method)) {
            Map<String, Object> map = New.map();
            map.put("value", "isAll");
            map.put("text", "全部");
            list.add(map);
        }
        view.toText(JsonUtils.toJson(list));
    }

    @WebRequest(action = "gender")
    public void QueryGender(HttpView view) throws ServletException, IOException {
        List<Map<String,Object>> list = New.list();
        String method = view.getParameter("method");
        if("query".equals(method)) {
            Map<String, Object> map0 = New.map();
            map0.put("value", "-1");
            map0.put("text", "不限");
            list.add(map0);
        }
        Map<String,Object> map1 = New.map();
        map1.put("value", "1");
        map1.put("text", "男");
        list.add(map1);
        Map<String,Object> map2 = New.map();
        map2.put("value","0");
        map2.put("text","女");
        list.add(map2);
        view.toText(JsonUtils.toJson(list));
    }


    @WebRequest(action = "marry")
    public void QueryMarry(HttpView view) throws ServletException, IOException {
        List<Map<String,Object>> list = New.list();
        String method = view.getParameter("method");
        if("query".equals(method)) {
            Map<String, Object> map0 = New.map();
            map0.put("value", "-1");
            map0.put("text", "不限");
            list.add(map0);
        }
        Map<String,Object> map1 = New.map();
        map1.put("value", "1");
        map1.put("text", "是");
        list.add(map1);
        Map<String,Object> map2 = New.map();
        map2.put("value","0");
        map2.put("text","否");
        list.add(map2);
        view.toText(JsonUtils.toJson(list));
    }

    @WebRequest(action = "department")
    public void QueryDepartment(HttpView view) throws ServletException, IOException {
        List<Map<String,Object>> list = jdbcTemplate.queryForListMap("select departmentId value, departmentName text from cw_Department");
        String method = view.getParameter("method");
//        if("query".equals(method)) {
//            Map<String, Object> map = New.map();
//            map.put("value", "isAll");
//            map.put("text","不限");
//            list.add(map);
//        }
        view.toText(JsonUtils.toJson(list));
    }
}
